import Immutable from 'seamless-immutable';
import * as types from '../constants/ActionTypes';
import helper from '../helper/pushCategoryHelper.js';

const pushCategory = Immutable.from({
  pushCategoryList: {},
  CategoryList: [],
  checkedItem: {},
  saveMsg: {}
});
export default function testCategoryReducer(state = pushCategory, action) {
  const { payload, type } = action;
  switch (type) {
    case types.FETCH_TEST_CATEGORY:
      return state.setIn(['pushCategoryList'], payload)
        .setIn(['CategoryList'], helper.addChecked(payload, state.checkedItem));
    case types.STORAGE_CHECKED:
      return state.setIn(['checkedItem'], payload);
    case types.RESTORE_PUSH_CATEGORY:
      return state.setIn(['checkedItem'], {});
    case types.SAVE_ERROR_MSG:
      return state.setIn(['saveMsg'], payload);
    default:
      return state;
  }
}
